﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using System.Text;
//using ProyectoFinal.Controles;

using ProyectoFinal.Controles;



public partial class frmCurso : System.Web.UI.Page
{
    String strcon = "";
    conPlanCurricular ctrPlan;
    conCurso ctrCurso;

    protected void Page_Load(object sender, EventArgs e)
    {


        strcon = ConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString;

        {
            if (!this.IsPostBack)
            {

                ctrPlan = new conPlanCurricular(strcon);

                DataView dv = new DataView(ctrPlan.ObtenerDatosFacultad());
                //DataView dv = new DataView(control.registrarDatosCurso());
                //DataView dv = new DataView(control.ObtenerCursosXFacultad(1));
                
                DropDownList1.DataSource = dv;
                DropDownList1.DataTextField = "nombre";
                DropDownList1.DataValueField = "codigo";
                DropDownList1.DataBind();
                DropDownList2.DataSource = dv;
                DropDownList2.DataTextField = "nombre";
                DropDownList2.DataValueField = "codigo";
                DropDownList2.DataBind();

            }
            lblmsg.Text = "";
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ctrCurso = new conCurso(strcon);

        DataTable dt = ctrCurso.ObtenerCursosXFacultad(Convert.ToInt32(DropDownList1.SelectedValue));

        /*if (dt.Rows.Count == 0)
            lblmsg.Text = "No se encontro resultados.";
        else
            lblmsg.Text = dt.Rows.Count + " resultados encontrados.";


        DataView dv = new DataView(dt);

        ListBox3.DataSource = dv;
        ListBox3.DataTextField = "nombre";
        ListBox3.DataValueField = "codigo";
        ListBox3.DataBind();
        ListBox1.DataSource = dv;
        ListBox1.DataTextField = "nombre";
        ListBox1.DataValueField = "codigo";
        ListBox1.DataBind();*/
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        ctrCurso = new conCurso(strcon);

        DataTable dt = ctrCurso.ObtenerCursosXFacultad(Convert.ToInt32(DropDownList2.SelectedValue));

        if (dt.Rows.Count == 0)
            lblmsg.Text = "No se encontro resultados.";
        else

            lblmsg.Text = dt.Rows.Count + " resultados encontrados.";

        DataView dv = new DataView(dt);

        ListBox3.DataSource = dv;
        ListBox3.DataTextField = "nombre";
        ListBox3.DataValueField = "codigo";
        ListBox3.DataBind();
        ListBox1.DataSource = dv;
        ListBox1.DataTextField = "nombre";
        ListBox1.DataValueField = "codigo";
        ListBox1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ctrCurso = new conCurso(strcon);

        /*
        List<int> cursos = new List<int>();

        foreach (ListItem i in ListBox4.Items)
        {
            cursos.Add(Convert.ToInt32(i.Value));
        }

        control.Grabar_Datos_Cursos(TextBox2.Text,Convert.ToInt32(DropDownList1.SelectedValue),Convert.ToInt32(ListBox4.SelectedValue),Convert.ToInt32(ListBox5.SelectedValue),tex
        //control.grabarDatosPC(TextBox1.Text, Convert.ToInt32(DropDownList1.SelectedValue),cursos);
        
        Label4.Text = "Datos fueron grabados";*/
        

        Curso nuevoCurso = new Curso(
                        Convert.ToString(TextBox2.Text),
                        Convert.ToString(TextBox3.Text),
                        Convert.ToString(TextBox7.Text),
                        Convert.ToInt32(TextBox6.Text),
                        Convert.ToInt32(TextBox4.Text),
                        Convert.ToInt32(TextBox5.Text),
                        //(ListBox5.SelectedItem.Value == null? null: Convert.ToInt32(ListBox5.SelectedItem.Value)),
                        //(ListBox4.SelectedItem.Value == null? null :Convert.ToInt32(ListBox4.SelectedItem.Value)),
                        Convert.ToInt32(ListBox5.SelectedItem.Value),
                        Convert.ToInt32(ListBox4.SelectedItem.Value),
                        Convert.ToInt32(DropDownList1.SelectedItem.Value));

        //ctrCurso = new conCurso(strcon);
                
        //nuevoCurso.nombre = Convert.ToString(TextBox2);
        //nuevoCurso.fk_facultad = Convert.ToInt32(DropDownList1.SelectedValue);
        //nuevoCurso.fk_prerrequisito = Convert.ToInt32(ListBox5.SelectedValue);
        //nuevoCurso.fk_equivalente = Convert.ToInt32(ListBox4.SelectedValue);
        //nuevoCurso.objetivo = Convert.ToString(TextBox3);
        //nuevoCurso.silabo = Convert.ToString(TextBox7);
        //nuevoCurso.h_teoricas = Convert.ToInt32(TextBox4);
        //nuevoCurso.h_practicas = Convert.ToInt32(TextBox5);
        //nuevoCurso.creditos = Convert.ToInt32(TextBox6);

        if (ctrCurso.GrabarDatosCursos(nuevoCurso))
        {
            Label4.Text = "Datos grabados exitosamente.";
        }
        else
        {
            Label4.Text = "Datos grabados exitosamente.";
        }
    }
    
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (ListBox4.SelectedValue == "")
            return;

        ListItem item = ListBox4.SelectedItem;

        ListBox4.Items.Remove(item);
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        if (ListBox1.SelectedValue == "")
            return;

        ListBox1.SelectionMode = ListSelectionMode.Multiple;

        ListItem item = ListBox1.SelectedItem;
        ListBox5.Items.Add(item);
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        if (ListBox5.SelectedValue == "")
            return;

        ListItem item = ListBox5.SelectedItem;

        ListBox5.Items.Remove(item);
    }
    protected void Button7_Click(object sender, EventArgs e)
    {
        if (ListBox3.SelectedValue == "")
            return;

        ListBox3.SelectionMode = ListSelectionMode.Multiple;

        ListItem item = ListBox3.SelectedItem;
        ListBox4.Items.Add(item);
    }
    protected void Button2_Click1(object sender, EventArgs e)
    {
        Response.Redirect("frmMain.aspx");
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {

    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void ListBox3_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void ListBox5_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void ListBox4_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    
}




//using System;
//using System.Data;
//using System.Configuration;
//using System.Collections;
//using System.Web;
//using System.Web.Security;
//using System.Web.UI;
//using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
//using System.Web.UI.HtmlControls;

//using System.Collections.Generic;
//using System.Text;

//using ProyectoFinal.Controles;


//public partial class frmCurso : System.Web.UI.Page
//{


//    String strcon = "";

//    protected void Page_Load(object sender, EventArgs e)
//    {
//        {

//            strcon = ConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString;

//            if (!this.IsPostBack)
//            {
//                conCurso control = new conCurso(strcon);

//                //DataView dv = new DataView(control.registrarDatosCurso());
//                DataView dv = new DataView(control.ObtenerCursosXFacultad(1));
                
//                DropDownList1.DataSource = dv;
//                DropDownList1.DataTextField = "nombre";
//                DropDownList1.DataValueField = "codigo";
//                DropDownList1.DataBind();

//            }
//            lblmsg.Text = "";
//        }
//    }

//    protected void Button1_Click(object sender, EventArgs e)
//    {
//        conCurso control = new conCurso(strcon);


//        List<int> cursos = new List<int>();

//        foreach (ListItem i in ListBox4.Items)
//        {
//            cursos.Add(Convert.ToInt32(i.Value));
//        }


//        Curso curso = new Curso(TxtNombre.Text,TextBox3.Text,TextBox1.Text,ListBox2.SelectedItem.Value,TextBox4.Text,TextBox5.Text,

//        control.Grabar_Datos_Cursos();

//        Label4.Text = "Datos fueron grabados";
//    }
//    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
//    {
//        conCurso control = new conCurso(strcon);

//        DataTable dt = control.ObtenerCursosXFacultad(Convert.ToInt32(DropDownList1.SelectedValue));

//        if (dt.Rows.Count == 0)
//            lblmsg.Text = "No se encontro resultados.";
//        else
//            lblmsg.Text = dt.Rows.Count + " resultados encontrados.";


//        DataView dv = new DataView(dt);

//        ListBox1.DataSource = dv;
//        ListBox1.DataTextField = "nombre";
//        ListBox1.DataValueField = "codigo";
//        ListBox1.DataBind();
//    }
//    protected void Button2_Click(object sender, EventArgs e)
//    {
//        if (ListBox4.SelectedValue == "")
//            return;

//        ListItem item = ListBox4.SelectedItem;

//        ListBox4.Items.Remove(item);
//    }
//    protected void Button5_Click(object sender, EventArgs e)
//    {
//        if (ListBox1.SelectedValue == "")
//            return;

//        ListBox1.SelectionMode = ListSelectionMode.Multiple;

//        ListItem item = ListBox1.SelectedItem;
//        ListBox5.Items.Add(item);
//    }
//    protected void Button6_Click(object sender, EventArgs e)
//    {
//        if (ListBox5.SelectedValue == "")
//            return;

//        ListItem item = ListBox5.SelectedItem;

//        ListBox5.Items.Remove(item);
//    }
//    protected void Button7_Click(object sender, EventArgs e)
//    {
//        if (ListBox3.SelectedValue == "")
//            return;

//        ListBox3.SelectionMode = ListSelectionMode.Multiple;

//        ListItem item = ListBox3.SelectedItem;
//        ListBox4.Items.Add(item);
//    }
//    protected void Button2_Click1(object sender, EventArgs e)
//    {
//        Response.Redirect("frmPlan.aspx");
//    }
//    protected void TextBox2_TextChanged(object sender, EventArgs e)
//    {

//    }
//    protected void ListBox4_SelectedIndexChanged(object sender, EventArgs e)
//    {

//    }
//}






